#!/usr/bin/perl -w

##HACKABOT_HELP##
# Yoda I am.
# !yoda phrase
##HACKABOT_HELP##

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;

my ($phrase, $asker);
while (<>) {
	if (/^nick\s*(\S*)/) {
		$asker = $1;
	}
	elsif (/^msg\s*(.*\S+)/) {
		$phrase = $1;
	}
}

if (defined $phrase and defined $asker) {
	my $r = (POST 'http://www.yodaspeak.co.uk/index.php',
		['YodaMe' => $phrase]);
	my $ua = LWP::UserAgent->new;
	my $y = $ua->request($r)->content;
	$y =~ s/.*YodaSpeak[^>]+>//s;
	print STDERR $y;
	$y =~ s/<.*//s;
	
	if ($y) {
		print "send $asker: $y\n";
	}
	else {
		print "send $asker: Not responding Yoda is\n";
	}
}
